package com.jsn.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.jsn.constants.GlobalConstants;

import java.io.IOException;

public class SmartAuth2ExceptionSerializer extends StdSerializer<SmartOAuth2Exception> {
    protected SmartAuth2ExceptionSerializer(Class<SmartOAuth2Exception> t) {
        super(t);
    }

    @Override
    public void serialize(SmartOAuth2Exception e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

        jsonGenerator.writeStartObject();
        jsonGenerator.writeObjectField("code", GlobalConstants.FAIL);
        jsonGenerator.writeStringField("msg", e.getMessage());

        jsonGenerator.writeEndObject();
    }
}
